#define _CRT_SECURE_NO_WARNINGS	

typedef struct TreeNode TreeNode;
int sum(TreeNode* root)
{
    if (root == NULL)
        return 0;
    return sum(root->left) + sum(root->right) + root->val;
}

int findTilt(struct TreeNode* root)
{
    if (root == NULL)
        return 0;
    return findTilt(root->left) + findTilt(root->right) + abs(sum(root->left) - sum(root->right));
}